package com.feiyisys.controller;

import com.feiyisys.common.Result;
import com.feiyisys.dto.UserLoginDTO;
import com.feiyisys.entity.Admin;
import com.feiyisys.entity.User;
import com.feiyisys.handlers.BaseContext;
import com.feiyisys.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统管理员表 前端控制器
 * </p>
 *
 * @author wq
 * @since 2025-10-10
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin("*")
public class AdminController {
    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody UserLoginDTO userLoginDTO) {
        String token = adminService.login(userLoginDTO);
        return Result.success(token);
    }

    @GetMapping("/info")
    public Result<Admin> getUserInfo() {
        Long id = BaseContext.getCurrentId();
        Admin admin = adminService.getById(id);
        return Result.success(admin);
    }

}
